﻿using System;
using System.Drawing.Design;
using System.Net;
using System.Windows.Forms;

using Argos.Windows.Forms;

namespace Argos.Design
{
	public class NetworkCredentialTypeEditor : UITypeEditor
	{

		public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			using (NetworkCredentialDialog dlg = new NetworkCredentialDialog())
			{
				if (value is NetworkCredential)
				{
					dlg.SelectedCredentials = (NetworkCredential)value;
				}

				if (dlg.ShowDialog() == DialogResult.OK)
				{
					return dlg.SelectedCredentials;
				}
			}
			return value;
		}

		public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
		{
			return UITypeEditorEditStyle.Modal;
		}

	}
}
